/**
 * 使用方法:
 引入YrTable.js和YrTable.css


 * 元素:<table id="tableid"> </table>

 * 调用方法:$("#tableid").newTable({
	parame1:.....,
	parame2:.....,
	parame3:.....,
	..............
});

 * 参数说明:
 =======================================================================================================================================
 * striped        类型:布尔     说明:开启条纹表格(默认开启)
 =======================================================================================================================================
 * serialNum      类型:布尔     说明:开启序列号(默认关闭)
 =======================================================================================================================================
 * monthReplace   类型:数组     说明:月份替换功能,[ 元素1(布尔)(是否开启),元素2(字符串)(需要替换的字段名) ] 例:[true,"fMonth"]
 =======================================================================================================================================
 * percentReplace 类型:数组     说明:小数替换成百分比,[ 元素1(布尔)(是否开启),元素2(字符串)(需要替换的字段名) ] 例:[true,"fRate"]
 =======================================================================================================================================
 * headerData     类型:对象     说明:控制将要展示的数据,{"字段名":"对应列名1","字段名2":"对应列名2".....} 例:{"factory":"厂区","fQty":"数量".......}
 =======================================================================================================================================
 * tableData      类型:数组     说明:源数据 格式:[{},{},{}.......]
 =======================================================================================================================================
 * totalCol       类型:数组     说明:需要合计的字段名 例:["fQty","fOrderQty"........]
 =======================================================================================================================================
 * totalByField   类型:数组     说明:按照某一字段归类插入合计行 [ 元素1(布尔)(是否开启归类合计),元素2(布尔)(是否开启总合计),元素3(字符串)(按照此字段名归类),元素4(字符串)(自定义归类合计的名称),元素5(字符串)(合计类型YR.SUM(默认)或YR.AVG) ] 例:[true, true, "fMonth", "合计", YR.SUM]
 =======================================================================================================================================
 * setJumpLink    类型:数组     说明:为单元格添加跳转链接
 [ 元素1(数组)(需要设置跳转链接的字段名),元素2(字符串)(将跳转的页面名称),元素3( 数组(对象元素) 例: [ {"",[""]} ] ) (为需要跳转的字段名绑定其他数据) ]
 例:[ ["factory","fMonth",.....],"aaa.html",[{"factory":["facCode","facID"]},{"fMonth":["fQty"]},......] ]
 ( 元素1 设置链接字段名必须和 元素3 对象中的Key名一致)

 * LinkExtras     类型:数组     说明:为链接增加额外参数 (2017.4.28)
 [ 元素1(对象),........ ]
 例:[{"paramName":"paramVal"}.........]
 =======================================================================================================================================
 * filterRow      类型:数组     说明:过滤表格内容  (2017.5.4)
 [ 元素1(布尔)(是否开启过滤),元素2(字符串)(按钮组ID),元素3(字符串)(需过滤的字段名) ]
 例:
 html: <div id="BtnGroup">
 <button>全部</button>
 <button>江头</button>
 <button>五里</button>
 <button>晋江</button>
 <button>五里服装</button>
 <button>江头服装</button>
 </div>
 [true,'BtnGroup','facName']
 =======================================================================================================================================
 * headerFixed    类型:布尔     说明:开启表头固定(默认开启) (2017.5.9)
 =======================================================================================================================================
 * lockColWidth   类型:json数组 说明:自定义表格列宽 (2017.5.22)
 例:[ {1,(列1|int类型|):"20px" (宽度|string类型|},{2,(列2|int类型|):"4.375rem"(宽度|string类型|)}]
 *单位自定义,可为px或rem
 rem = px / 16
 |  px  |     rem       |
 ------------------------
 |  12  | 12/16 = .75   |
 |  14  | 14/16 = .875  |
 |  16  | 16/16 = 1     |
 |  18  | 18/16 = 1.125 |
 |  20  | 20/16 = 1.25  |
 |  24  | 24/16 = 1.5   |
 |  30  | 30/16 = 1.875 |
 |  36  | 36/16 = 2.25  |
 |  42  | 42/16 = 2.625 |
 |  48  | 48/16 = 3     |
 |  70  | 70/16=4.375   |
 -------------------------
 * cellAddPram    类型：json数组 说明：为某列单元格单独绑定属性(2017.6.5)
 例:[ {"需绑定字段名1" : [ { "参数名1" : "参数值1" } , { "参数名1" : "参数值2" }]},......]
 =======================================================================================================================================
 * 2017-6-5 version=1.6
 * 9527Lin
 * **/

(function ($) {
    $.fn.newTable = function (_options) {
        var v = mui.parseUrl();
        var userID = v["id"];
        var loginCode = v["loginCode"];
        var _default = {
            striped: true,
            serialNum: false,
            headerFixed: true,
            headerSort: true,
            monthReplace: [false, ""],
            percentReplace: [false, ""],
            totalByField: [false, false, "", "", ""],
            cellAddPram: [],
            headerData: {
                "": ""
            },
            tableData: [{
                "": ""
            }],
            totalCol: [""],
            setJumpLink: [
                [""], "", [{
                    "": ""
                }],

            ],
            LinkExtras: [{}, {}],
            filterRow: [false, "", ""],
            dragCol: false,
            lockColWidth: [{}]
        }
        var _options = $.extend(_default, _options);
        var _headArrLength = Object.keys(_options.headerData).length;
        var _dataArrLength = _options.tableData.length;
        var _totalArrLength = _options.totalCol.length;

        return this.each(function () {
            $(this).addClass("table table-bordered");
            creatTabHader(this, _options.tableData);
            creatTabBody(this, _options.tableData);
            if (_options.serialNum) {
                addSerialNum(this)
            }
            ;
            if (_options.cellAddPram) {
                cellAddPram();
            }
            ;
            if (_options.setJumpLink != "") {
                BuilderLink(this, _options.setJumpLink[0], _options.setJumpLink[1], _options.setJumpLink[2], _options.tableData, _options.LinkExtras)
            }
            ;
            if (_options.totalCol != "") {
                if (_options.totalByField[0]) {
                    addTotalRowByField(this, _options.totalByField[1], _options.totalByField[2], _options.totalByField[3], _options.totalByField[4], _options.totalCol, _options.tableData)
                } else {
                    addTotalRow(this)
                }
            }
            ;
            if (_options.percentReplace[0]) {
                percentReplace(this, _options.percentReplace[1])
            }
            if (_options.filterRow[0]) {
                filterRow(this, _options.filterRow[1], _options.filterRow[2], _options.tableData)
            }
            ;
            if (_options.striped) {
                stripedRow();
            }
            ;
            if (_options.headerFixed) {
                thFixed();
            }
            if (_options.lockColWidth) {
                lockColWidth(_options.lockColWidth)
            }
        });
        //创建表头
        function creatTabHader(_el, _data) {
            var _html = "";
            var _fieldNameArr = [];
            var tmpNum = 0;
            _html += "<thead class='rowHeader'><tr data-type=title>";
            //将表头和相应字段名加属性绑定用于定位
            for (var x in _options.headerData) {
                _html += "<th data-name='" + x + "'>" + _options.headerData[x] + "</th>";
                tmpNum++;
            }
            _html += "</tr></thead>";
            $(_el).append(_html);
        }

        //添加数据
        function creatTabBody(_el, _data) {
            var _html = "";
            _html += "<tbody>";
            var tmpNum = 0
            for (var i = 0; i < _dataArrLength; i++) {
                _html += "<tr>"
                for (var x in _options.headerData) {
                    if (_options.monthReplace[0]) {
                        if (x == _options.monthReplace[1]) {
                            _html += "<td data-fieldName='" + x + "'>" + MonthReplace(_data[i][x]) + "</td>";
                        } else {
                            _html += "<td data-fieldName='" + x + "'>" + _data[i][x] + "</td>";
                        }
                    } else {
                        _html += "<td data-fieldName='" + x + "'>" + _data[i][x] + "</td>";
                    }
                    tmpNum++;
                }
                _html += "</tr>"
            }
            _html += "</tbody>";
            $(_el).append(_html);
        };
        //隔行换色
        function stripedRow() {
            var _tmpTrV = "";
            if (_options.totalByField[0]) {
                $('table').find('tbody tr:visible:not([data-type=alltotal])').removeClass('info');
            } else {
                _tmpTrV = $('table').find('tbody tr:visible:not([data-type=alltotal]):not([data-type=total])');
                _tmpTrV.removeClass("info");
            }

            var _tmpTrVLen = _tmpTrV.length;
            for (var i = 0; i < _tmpTrVLen; i++) {
                if (i % 2 == 0) {
                    _tmpTrV.eq(i).addClass("info");
                }
            }
        }

        //添加序号列
        function addSerialNum(_el) {
            $('table').find("tr:first").prepend("<th data-name='SerialNum'>序号</th>");
            for (var i = 0; i < _dataArrLength; i++) {
                $('table').find("tr").eq(i + 1).prepend("<td>" + (i + 1) + "</td>");
            }
            ;
            if (_options.serialNum) {
                _headArrLength++;
            }
        }

        //表头固定
        function thFixed() {
            var _tabHeight = $('table').height();
            var _clongTh = $('table').find('thead').clone(true);
            var _tmpTable = $("<table id='_tmpTable' style='margin-bottom:0px;position: fixed;' class='table table-bordered'></table>").html(_clongTh);
            $(window).scroll(function () {
                var _scrollLen = $(window).scrollTop();
                if (_scrollLen >= 44 && _scrollLen < _tabHeight) {
                    $('.mui-content').prepend(_tmpTable);
                }
                else if (_scrollLen < 44 || _scrollLen >= _tabHeight) {
                    $('#_tmpTable').remove();
                }
            })
        };
        //添加合计行
        function addTotalRow(_el) {
            var _html = "";
            _html += "<tr data-type=total class='danger'>"
            for (var i = 0; i < _headArrLength; i++) {
                if (i === 0) {
                    _html += "<td>合计</td>"
                } else {
                    _html += "<td></td>"
                }
            }
            _html += "</tr>"
            $(_el).append(_html);
            joinTotalNum(_el);
            //填充需合计单元格数据
            function joinTotalNum(_el) {
                for (var i = 0; i < _totalArrLength; i++) {
                    var _colPos = colPosition(_el, _options.totalCol[i])
                    $(_el).find("tr:last").find("td").eq(_colPos).html(cellSum(_options.totalCol[i]))
                }
            }

            //合计单元格求和
            function cellSum(_keyName) {
                var sum = 0;
                for (var i = 0; i < _dataArrLength; i++) {
                    var tmp = 0;
                    for (var x in _options.tableData[i]) {
                        if (x === _keyName) {
                            tmp = _options.tableData[i][x];
                            break;
                        }
                    }
                    sum += parseFloat(tmp);
                }
                return Math.round(sum*100)/100;
            };
        }

        //按某字段归类合计
        function addTotalRowByField(_el, _isAllTotal /*是否开启归类合计*/, _classField /*需要归类字段名*/, _totalClassName /*自定义归类命*/, _totalTypeName /*合计类型*/, _totalField /*需要合计的字段*/, _data /*源数据*/) {
            //获取需要归类合计字段名的所有情况
            var _dataLength = _data.length;
            var _classFieldArr = [];
            for (var i = 0; i < _dataLength; i++) {
                if (_classFieldArr.indexOf(_data[i][_classField]) == -1) {
                    _classFieldArr.push(_data[i][_classField]);
                }
            }
            var _classFieldArrLen = _classFieldArr.length;
            var _tmpNum = 0;
            var _tr = $(_el).find("tr")
            var _html = "<tr data-type='total' class='danger'>"
            for (var k = 1; k < _headArrLength; k++) {
                if (k == 1) {
                    if (typeof(_totalClassName) == "undefined") {
                        _totalClassName = "合计";
                    }
                    _html += "<td>" + _totalClassName + "</td>"
                }
                _html += "<td></td>"
            }
            for (var i = 0; i < _classFieldArrLen; i++) {
                for (var j = _tmpNum; j < _dataLength; j++) {
                    if (_classFieldArr[i] != _data[j][_classField]) {
                        _tmpNum = j;
                        _tr.eq(j).after(_html).next().attr("trnum", j)
                        break
                    }
                    //最后一种classfield的合计
                    else if (j == _dataLength - 1) {
                        _tr.eq(j + 1).after(_html).next().attr("trnum", j + 1)
                    }
                }
            }
            //添加总合计
            if (_isAllTotal) {
                _tr.eq(_dataLength).after(_html).next().attr("trnum", _dataLength)
                $(_el).find("tr:last").attr("class", "info").attr("data-type", "alltotal").find("td").eq(0).text("总" + _totalClassName)
            }
            //生成数据位置段
            var _totalTr = $(_el).find('tr[data-type=total]');
            var _totalTrLen = $(_el).find('tr[data-type=total]').length;
            var _startIndex = 0;
            var _endIndex = 0;
            var _dataIndex = [];
            for (var i = -1; i < _totalTrLen - 1; i++) {
                var _indexArr = [];
                if (i == -1) {
                    _startIndex = 0
                } else {
                    _startIndex = parseInt(_totalTr.eq(i).attr("trnum"))
                }
                _endIndex = parseInt(_totalTr.eq(i + 1).attr("trnum"))
                _indexArr.push(_startIndex, _endIndex);
                _dataIndex.push(_indexArr);
            }
            //生成将对应数据段的数据放入数组
            var _dataIndexLen = _dataIndex.length;
            var _dataArr = [];
            for (var i = 0; i < _dataIndexLen; i++) {
                var _tmpArr = [];
                for (var j = _dataIndex[i][0]; j < _dataIndex[i][1]; j++) {
                    _tmpArr.push(_data[j][_totalField]);
                }
                _dataArr.push(_tmpArr);
            }

            //数组求和
            var _sumArr = [];
            var _avgArr = [];
            var _dataArrLen = _dataArr.length;
            for (var i = 0; i < _dataArrLen; i++) {
                var _Len = _dataArr[i].length;
                var _sum = 0;
                for (var j = 0; j < _Len; j++) {
                    _sum += parseFloat(_dataArr[i][j])
                }
                _sumArr.push(_sum);
            }
            if (_totalTypeName == "avg") {
                var _dataIndexLen = _dataIndex.length;
                for (var i = 0; i < _dataIndexLen; i++) {
                    var _itemLen = _dataIndex[i][1] - _dataIndex[i][0]
                    var _avg = _sumArr[i] / _itemLen;
                    _avgArr.push(_avg)
                }
            }
            //将数据填充至单元格中
            var _trNew = $(_el).find('tr[trnum]')
            var _tr = $(_el).find("tr")
            var _totalNum = _sumArr.reduce(function (x, y) {
                return x + y;
            })
            if (_totalTypeName == "avg") {
                for (var i = 0; i < _dataIndexLen; i++) {
                    _trNew.eq(i).find('td:last').html(numConversion(_avgArr[i]))
                }
                _tr.last().find("td:last").html(numConversion(_totalNum / _dataLength))
            } else {
                for (var i = 0; i < _dataIndexLen; i++) {
                    _trNew.eq(i).find('td:last').html(numConversion(_sumArr[i]))
                }
                _tr.last().find("td:last").html(numConversion(_totalNum))
            }
        }

        //生成跳转链接
        function BuilderLink(_el, _fieldName, _pageName, _bindData, _data, _ExtrasObj) {
            var _Link = "";
            var _header = $(_el).find("tr th");
            var _headerLength = $(_el).find("tr th").length;
            var _JumpLinkFieldLength = _fieldName.length;
            if (_pageName.slice(-5) === ".html" || _pageName.slice(-5) === ".HTML") {
                _Link = _pageName + "?";
            } else {
                _Link = _pageName + ".html?";
            }
            bindDataProperty(_el, _bindData, _data)
            addATag(_el, _fieldName);
            bindEven(_bindData, _data)
            //内部方法:输出构造链接
            function outputLink(_Link, _valObj) {
                var i = 0;
                for (var x in _valObj) {
                    i++;
                    if (i == 1) {
                        _Link += x + "=" + _valObj[x];
                    } else {
                        _Link += "&" + x + "=" + _valObj[x];
                    }
                }
                return _Link;
            }

            //内部方法:添加a标签
            function addATag(_el, _fieldName) {
                for (var i = 0; i < _headerLength; i++) {
                    for (var j = 0; j < _JumpLinkFieldLength; j++) {
                        if (_header.eq(i).attr("data-name") === _fieldName[j]) {
                            for (var k = 1; k < _dataArrLength + 1; k++) {
                                var tmpText = $(_el).find("tr").eq(k).find("td").eq(i).text()
                                $(_el).find("tr").eq(k).find("td").eq(i).html("<a item-Index=" + (k - 1) + " data-Type='Alink'>" + tmpText + "</a>")
                            }
                        }
                    }
                }
                ;
            }

            //内部方法:绑定a标签点击事件
            function bindEven(_bindData, _data) {
                var _bindDataLength = _bindData.length;
                var _a = _el.querySelectorAll("tr td a");
                var _aLen = _a.length;
                for (var i = 0; i < _aLen; i++) {
                    _a[i].addEventListener('tap', function () {
                        var _tmpObj = new Object;
                        var _ItemIndex = $(this).attr("item-Index")
                        for (var n = 0; n < _bindDataLength; n++) {
                            for (var x in _bindData[n]) {
                                if ($(this).parent().attr("data-fieldname") === x) {
                                    var _bindLength = _bindData[n][x].length;
                                    for (var m = 0; m < _bindLength; m++) {
                                        var _tmpFieldName = _bindData[n][x][m]
                                        _tmpObj[_tmpFieldName] = _options.tableData[_ItemIndex][_tmpFieldName]
                                    }
                                }
                            }
                        }
                        _tmpObj.isCall = true;
                        _tmpObj.id = userID;
                        _tmpObj.loginCode = loginCode;
                        if (_ExtrasObj != "") {
                            var _LinkExtraLen = _ExtrasObj.length;
                            for (var i = 0; i < _LinkExtraLen; i++) {
                                for (var x in _ExtrasObj[i]) {
                                    _tmpObj[x] = _ExtrasObj[i][x];
                                }
                            }
                        }
                        window.location.href = outputLink(_Link, _tmpObj);
                    })
                }
            }

            //单元格数据-属性绑定
            function bindDataProperty(_el, _bindData, _data) {
                var _th = $(_el).find("tr").find("th")
                var _thLength = _th.length;
                var _bindDataLength = _bindData.length
                for (var i = 0; i < _bindDataLength; i++) {
                    for (var x in _bindData[i]) {
                        var _bindLength = _bindData[i][x].length;
                        for (var n = 0; n < _bindLength; n++) {
                            for (var j = 0; j < _thLength; j++) {
                                if (x === _th.eq(j).attr("data-name")) {
                                    //遍历源数据,需要绑定的字段添加到单元格属性
                                    for (var k = 0; k < _dataArrLength; k++) {
                                        $(_el).find("tr").eq(k + 1).find("td").eq(j).attr(_bindData[i][x][n], _data[k][_bindData[i][x][n]])
                                    }
                                }
                            }
                        }
                    }
                }
            }
        };
        //单独为单元格绑定数据
        function cellAddPram() {
            var _fieldAndObj = _options.cellAddPram;
            var _fAOLen=_fieldAndObj.length;
            var _tab = $('table')
            var _tabLen = _tab.find('tbody tr').length;
            for (var i=0; i < _fAOLen; i++) {//遍历参数数组
                for (var x in _fieldAndObj[i]){//遍历参数数组对象
                    for (var j = 0; j < _tabLen; j++) {//遍历表格tr
                        var _Len=_fieldAndObj[i][x].length
                        for (var k=0;k<_Len;k++){//遍历参数数组中对象中的数组
                            for (var m in _fieldAndObj[i][x][k]){//遍历参数数组中对象中的数组的值
                                _tab.find('tbody tr').eq(j).find('td').eq(colPosition(_tab,x)).attr(m,_fieldAndObj[i][x][k][m])
                            }
                        }

                    }
                }

            }

        }
        //过滤
        function filterRow(_el, _BtnGroupID, _filterField, _data) {
            var _AllFilterArr = [];
            for (var i = 0; i < _dataArrLength; i++) {
                for (var x in _data[i]) {
                    if (x === _filterField) {
                        if (_AllFilterArr.indexOf(_data[i][x]) == -1) {
                            _AllFilterArr.push(_data[i][x])
                        }
                    }
                }
            }
            var _BtnGroup = document.getElementById(_BtnGroupID).querySelectorAll("button");
            var _BtnGroupLen = _BtnGroup.length;
            var _dataLen = _data.length;
            for (var i = 0; i < _BtnGroupLen; i++) {
                _BtnGroup[i].addEventListener('tap', function () {
                    var _BtnContent = $(this).html();
                    var _tmpTr = $('table').find('tbody tr:not([data-type])');
                    //开启分类合计的情况
                    if (_options.totalByField[0]) {
                        //不是全部按钮情况
                        if (_BtnContent !== "全部") {
                            //隐藏Tr和相应合计行
                            hideTr();
                            hideTr().hide();
                            reTable();
                        }
                        //按下全部按钮情况
                        else {
                            var _Tr = $('table').find('tbody tr:not([data-type=alltotal])');
                            var _TrLen = _Tr.length;
                            for (var i = 0; i < _TrLen; i++) {
                                _Tr.eq(i).show();
                            }
                            reTable();
                        }
                    }
                    //没有开启分类合计的情况
                    else {
                        //不是全部按钮情况
                        if (_BtnContent !== "全部") {
                            hideTr();
                            reTable();
                        }
                        //按下全部按钮情况
                        else {
                            for (var i = 0; i < _dataLen; i++) {
                                _tmpTr.eq(i).show();
                            }
                            reTable();
                        }
                    }
                    //重新渲染表格
                    function reTable() {
                        //条纹表格
                        stripedRow();
                        //重排序号
                        reNum();
                        reTotal();
                    }

                    //隐藏Tr
                    function hideTr() {
                        var _totalRow = "";
                        for (var i = 0; i < _dataLen; i++) {
                            var _dataObjLen = _data[i].length; //_data内部对象长度
                            if (_BtnContent === _data[i][_filterField]) {
                                _tmpTr.eq(i).hide();
                                _totalRow = _tmpTr.eq(i).next();
                            }
                        }
                        return _totalRow;
                    }

                    //序号重排
                    function reNum() {
                        var _tmpTrV = $('table').find('tbody tr:not([data-type]):visible');
                        var _tmpTrVLen = _tmpTrV.length;
                        //数字排序
                        if (_options.serialNum) {
                            for (var i = 0; i < _tmpTrVLen; i++) {
                                _tmpTrV.eq(i).find('td').eq(0).html("").html(i + 1);
                            }
                        }
                    }

                    //重新计算合计值
                    function reTotal() {
                        var _Tr = "";
                        var _TrLen = 0;
                        var _fieldArr = _options.totalCol;
                        var _fieldArrLen = _fieldArr.length;
                        var _col = 0;
                        _Tr = $('table').find('tbody tr:not([data-type=total]):not([data-type=alltotal]):visible')
                        _TrLen = _Tr.length;
                        for (var i = 0; i < _fieldArrLen; i++) {
                            var _sumNum = 0;
                            _col = colPosition($('table'), _fieldArr[i]);
                            for (var j = 0; j < _TrLen; j++) {
                                var _tmpNum = 0;
                                _tmpNum = _Tr.eq(j).find('td').eq(_col).text();
                                _sumNum += parseFloat(_tmpNum);
                            }
                            if (_options.totalByField[4] === "avg") {
                                $('table').find('tbody tr:last').find('td').eq(_col).html(numConversion(_sumNum / _Tr.length))
                            } else {
                                $('table').find('tbody tr:last').find('td').eq(_col).html(Math.round(_sumNum*100)/100)
                            }
                        }
                    }
                })
            }
        }

        //锁定列宽
        function lockColWidth(_WidthArr) {
            var _aa = new thFixed();
            _aa._clongTh = $('table').find('thead').clone(true);
            var _el = $('table tr th')
            var _Len = _WidthArr.length
            for (var i = 0; i < _Len; i++) {
                for (var x in _WidthArr[i]) {
                    $(_el).eq(x - 1).css("width", "" + _WidthArr[i][x] + "")
                }
            }
        }

        //月份替换
        function MonthReplace(MonthStr) {
            if (MonthStr.slice(4, 6) == "01") {
                return "一月"
            } else if (MonthStr.slice(4, 6) == "02") {
                return "二月";
            } else if (MonthStr.slice(4, 6) == "03") {
                return "三月";
            } else if (MonthStr.slice(4, 6) == "04") {
                return "四月";
            } else if (MonthStr.slice(4, 6) == "05") {
                return "五月";
            } else if (MonthStr.slice(4, 6) == "06") {
                return "六月";
            } else if (MonthStr.slice(4, 6) == "07") {
                return "七月";
            } else if (MonthStr.slice(4, 6) == "08") {
                return "八月";
            } else if (MonthStr.slice(4, 6) == "09") {
                return "九月";
            } else if (MonthStr.slice(4, 6) == "10") {
                return "十月";
            } else if (MonthStr.slice(4, 6) == "11") {
                return "十一月";
            } else if (MonthStr.slice(4, 6) == "12") {
                return "十二月";
            }
        }

        function percentReplace(_el, _field) {
            var _colIndex = colPosition(_el, _field);
            var _tr = $(_el).find('tr')
            for (var i = 1; i < _tr.length; i++) {
                var _text = _tr.eq(i).find('td:last').text();
                var _newText = (parseFloat(_text) * 100).toFixed(1) + "%"
                _tr.eq(i).find('td:last').html(_newText)
            }
        }

        //根据字段名定位列
        function colPosition(_el, _field) {
            var _tabHead = $(_el).find("tr:first").find("th");
            var _tabHeadLnegth = $(_el).find("tr:first").find("th").length;
            for (var j = 0; j < _tabHeadLnegth; j++) {
                if (_field == _tabHead.eq(j).attr("data-name")) {
                    return j
                }
            }
            return -1;
        }

        //小数个数转换
        function numConversion(_num) {
            if (_num.toString().indexOf(".") == -1) {
                return _num;
            } else if (_num.toString()[1].length > 0) {
                return _num.toFixed(2);
            }
            return _num;
        }
    }
})(jQuery)